<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input type="button" value="-" @click="sub()">
        <span>{{num}}</span>
        <input type="button" value="+" @click="add()">
    </div>
    <!-- 开发环境版本，包含了有帮助的命令行警告 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        let v = new Vue({
            el:"#app",
            data:{
                num:1
            },
            methods:{
                add(){
                    if (this.num < 10) {
                        this.num++;
                    } else {
                        alert("已经到最大值了");
                    }
                },
                sub(){
                    if (this.num > 0) {
                        this.num--;
                    } else {
                        alert("已经到最小值了");
                    }
                }
            }
        })
    </script>
</body>

</html>